package com.gmall.product.controller;


import com.gmall.common.result.PageInfo;
import com.gmall.common.result.Result;
import com.gmall.model.product.BaseAttrInfo;
import com.gmall.product.service.BaseAttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/product/baseAttr")
public class BaseAttrController {


    @Autowired
    private BaseAttrService baseAttrInfoService;

    @GetMapping({"attrInfoList/{pageNo}/{pageSize}/{category1Id}",
            "attrInfoList/{pageNo}/{pageSize}/{category1Id}/{category2Id}",
            "attrInfoList/{pageNo}/{pageSize}/{category1Id}/{category2Id}/{category3Id}"}
    )
    public Result<PageInfo<BaseAttrInfo>> attrInfoList(@PathVariable Integer pageNo,
                                                        @PathVariable Integer pageSize,
                                                        @PathVariable Long category1Id,
                                                       @PathVariable(required = false) Long category2Id,
                                                       @PathVariable(required = false) Long category3Id){

        return baseAttrInfoService.attrInfoList2(pageNo,pageSize,category1Id,category2Id,category3Id);
    }

    @PostMapping("save")
    public Result<String> save(@RequestBody BaseAttrInfo baseAttrInfo){
        return baseAttrInfoService.save(baseAttrInfo);
    }

    @DeleteMapping("remove/{attrId}")
    public Result<String> remove(@PathVariable Long attrId){
        return baseAttrInfoService.remove(attrId);
    }
}
